<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head>
<!--Converted with LaTeX2HTML 98.1 release (February 19th, 1998)
originally by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->


<title>Anagrams (II)</title>
<meta name="description" content="Anagrams (II)">
<meta name="keywords" content="htmlatex">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="STYLESHEET" href="acm-00630_files/htmlatex.css">
</head><body bgcolor="#ffffff" lang="EN">

<h1><br clear="all"><center><table bgcolor="#0060f0"><tbody><tr><td><b><font color="#c0ffff" size="5">&nbsp;<a name="SECTION0001000000000000000000">
Anagrams (II)</a>&nbsp;</font></b></td></tr></tbody></table></center>
</h1>

<p>
One of the preferred kinds of entertainment of people living in final stages
of XX century is filling in the crosswords. Almost every newspaper and
magazine has a column dedicated to entertainment but only amateurs have enough
after solving one crossword. Real professionals require more than one
crossword for a week. And it is so dull - just crosswords and crosswords -
while so many other riddles are waiting out there. For those are special,
dedicated magazines. There are also quite a few competitions to take part in,
even reaching the level of World Championships. Anyway - a lot.

</p><p>

</p><p>
<br>
You were taken on by such a professional for whom riddle solving competing is
just a job. He had a brilliant idea to use a computer in work not just to
play games. Somehow anagrams found themselves first in the line. You are to
write a program which searches for anagrams of given words, using a given
vocabulary, tediously filled with new words by yours employer.

</p><p>

</p><h2><font color="#0070e8"><a name="SECTION0001001000000000000000">
Input</a>&nbsp;</font>
</h2>
The first line of the input is an integer M, then a blank line followed by M datasets. There is a blank line between datasets.

The structure of each dataset is given below:

<p>
</p><pre>&lt;number of words in vocabulary&gt;
&lt;word 1&gt;
..............
&lt;word N&gt;
&lt;test word 1&gt;
................
&lt;test word k&gt;
END
</pre>

<p>

<code>&lt;number of words in vocabulary&gt;</code> is an integer number <i>N</i> &lt; 1000. <code>&lt;word 1&gt;</code> up
to <code>&lt;word N&gt;</code> are words from the vocabulary. <code>&lt;test word 1&gt;</code> up to <code>&lt;test word k&gt;</code>
are the words to find anagrams for. All words are lowercase (word END means
end of data - it is NOT a test word). You can assume all words are not
longer than 20 characters.

</p><p>

</p><h2><font color="#0070e8"><a name="SECTION0001002000000000000000">
Output</a>&nbsp;</font>
</h2>
For each <code>&lt;test word&gt;</code> list the found anagrams in the following way:

<p>
</p><pre>Anagrams for: &lt;test word&gt;
&lt;No&gt;) &lt;anagram&gt;
...............
</pre>

<p>

<code>&lt;No&gt;</code> should be printed on 3 chars.

</p><p>
In case of failing to find any anagrams your output should look like this:

</p><p>
</p><pre>Anagrams for: &lt;test word&gt;
No anagrams for: &lt;test word&gt;
</pre>

<p>Print a blank line between datasets.

</p><h2><font color="#0070e8"><a name="SECTION0001003000000000000000">
Sample Input</a>&nbsp;</font>
</h2>

<p>
</p><pre>1

8
atol
lato
microphotographics
rata
rola
tara
tola
pies
tola
kola
aatr
photomicrographics
END
</pre>

<p>

</p><h2><font color="#0070e8"><a name="SECTION0001004000000000000000">
Sample Output</a>&nbsp;</font>
</h2>
				
<pre>Anagrams for: tola
  1) atol
  2) lato
  3) tola
Anagrams for: kola
No anagrams for: kola
Anagrams for: aatr
  1) rata
  2) tara
Anagrams for: photomicrographics
  1) microphotographics
</pre>

<p>

</p><p>
<br></p><hr>
<address>
<i>Miguel A. Revilla</i>
<br><i>2000-01-10</i>
</address>
</body></html>